package com.atguigu.jxc.service.impl;

import com.atguigu.jxc.dao.SupplierDao;
import com.atguigu.jxc.entity.Supplier;
import com.atguigu.jxc.service.SupplierService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SupplierServiceImpl implements SupplierService {

    @Autowired
    private SupplierDao supplierDao;

    @Override
    public PageInfo<Supplier> list(Integer page, Integer rows, String supplierName) {
        PageHelper.startPage(page,rows);
        List<Supplier> list = supplierDao.list(supplierName);
        PageInfo pageInfo = new PageInfo(list);
        return pageInfo;
    }

    @Override
    public void save(Supplier supplier) {
        if(supplier.getSupplierId() == null){
            // 添加供应商
            supplierDao.addSupplier(supplier);
        }else {
            // 修改供应商
            supplierDao.updateSupplier(supplier);
        }
    }

    @Override
    public void delete(String[] ids) {
        if(ids!=null && ids.length>0){
            for (String id : ids) {
                supplierDao.deleteById(id);
            }
        }
    }
}
